package DAO;

import javafx.scene.control.Label;
import javafx.scene.control.OverrunStyle;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 思维导图的一个节点
 */
public class TreeNode extends Label{
    private String tex; // 文本内容

    private int pid;  // 该节点的父节点的id

    private int nid;   // 该节点的id
    private int pos = 1; // 设置标记(position)，该节点是左节点，还是右节点

    private double x=0;     // 设置横坐标

    private double y=0;     // 设置纵坐标

    private boolean click = false;  // 判断是否被单击

    private List<TreeNode> nodeChildren = new ArrayList<>();  // 该节点的儿子节点

    // 以pid,text为参数的构造方法
    public TreeNode(int pid,String text){
        super(text);
        this.pid = pid;
        this.tex=text;
        this.setStyle( // style样式
                "-fx-background-color:#FAEBD7;" +
                        "-fx-background-radius:10;" +
                        "-fx-padding:10"
        );
        this.setMaxSize(200, 80); // 设置大小
        this.setWrapText(true);  // 自动换行
        this.setTextAlignment(TextAlignment.CENTER); // 文本的对齐方式，将文本居中显示
        this.setTextOverrun(OverrunStyle.ELLIPSIS);  // 当文本过长时的省略样式，即超出节点宽度时采用省略号表示
        this.setTextFill(Color.WHITE);  // 设置字体为白色
        this.setFont(new Font("Arial",20)); // 设置显示的字体格式
    }

    // 无参的构造方法
    public TreeNode() {
        super();
        this.setStyle(
                "-fx-background-color:#FAEBD7;"	+
                        "-fx-background-radius:10;"+
                        "-fx-padding:10;"
        );
        this.setMaxSize(200, 80);
        this.setWrapText(true);
        this.setTextAlignment(TextAlignment.CENTER);
        this.setTextOverrun(OverrunStyle.ELLIPSIS);
        this.setTextFill(Color.WHITE);
        this.setFont(new Font("Arial",20));
    }


    // get set 方法
    public int getNid() {
        return nid;
    }

    public void setNid(int nid) {
        this.nid = nid;
    }

    public int getPos() {
        return pos;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    public String getTex() {
        return tex;
    }

    public void setTex(String tex) {
        this.tex = tex;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public List<TreeNode> getNodeChildren() {
        return nodeChildren;
    }

    public void setNodeChildren(List<TreeNode> nodeChildren) {
        this.nodeChildren = nodeChildren;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public boolean isClick() {
        return click;
    }

    public void setClick(boolean click) {
        this.click = click;
    }
}


